import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { BusiProvider } from '../../providers/busi/busi';
import { NativeProvider } from '../../providers/native/native';
import { SocialSharing } from '@ionic-native/social-sharing';
import { Global } from '../../common/global';

/**
 * Generated class for the MettingdetailPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-mettingdetail',
  templateUrl: 'mettingdetail.html',
})
export class MettingdetailPage {
  mettingdetil:any;
  sfsh:boolean = false;
  usertype="0";
  intype:any;
  wfq="0";
  mettingid:any;
  constructor(public navCtrl: NavController, public navParams: NavParams,public busi: BusiProvider,private native:NativeProvider,
    private socialSharing: SocialSharing) {
    this.mettingid = this.navParams.get("mettingid");
    this.usertype = localStorage.getItem(Global.usertype);
    this.intype = this.navParams.get("intype");
    this.wfq = this.navParams.get("wfq");
  }

  ionViewDidEnter(){
    this.getmettingDetail();
  }
  ionViewDidLoad() {
    console.log('ionViewDidLoad MettingdetailPage');
  }

  mettingsh(){
    console.log(this.mettingdetil);
    this.busi.mettingsh(this.mettingdetil.id).subscribe(
      ()=>{
        this.native.showToast("审核成功");
        this.navCtrl.pop();
      },err=>{

      }
    );
  }
  share(){
    let message="会议主题:\n"+this.mettingdetil.topic+"\n\n"+"会议时间:\n"+this.mettingdetil.kssj+"\n\n"+
    "会议描述:\n"+this.mettingdetil.desc;
    this.socialSharing.share(message).then(
      ()=>{
      }
    )
  }
  downfile(){
    let url = localStorage.getItem("address") +"upload/"+this.mettingdetil.zlurl;
    this.native.openUrlByBrowser(url);
  }

  checkinmetting(){
    this.busi.getCurrentUserDetail().subscribe(
      data=>{
        this.navCtrl.push("MettingchatPage",{metting:this.mettingdetil,userinfo:data.userdetail}).then(
          ()=>{
            this.native.showToast("签到成功!",3000,'center');
          }
        )
      },error=>{

      })
  }
  addsummary(){
    this.navCtrl.push("SummaryPage",{mettingid:this.mettingdetil.id,hyzj:this.mettingdetil.hyzj});
  }

  getmettingDetail(){
    this.busi.getMettingDetail(this.mettingid).subscribe(
      data=>{
        this.mettingdetil = data.metting;
        this.sfsh = this.mettingdetil.sfsh=='1'?true:false;
      },
      err=>{

      }
    );
  }

}
